import { defineStore } from "pinia";
import { deepClone } from "@bis/utils/objectFun";
import QuestionType from "@bis/types/question";

const defaultFormConfig = {
  id: null,
  name: "",
  description: "",
  formDepotId: 0, // 表单仓库ID
};

export const useFormStore = defineStore("formJsonStore", {
  state: () => {
    return {
      formConfig: deepClone(defaultFormConfig),
      questions: <QuestionType[]>[],
      selectQuestion: <QuestionType>null,
      isDesigner: false, // 是否是设计台
    };
  },
  actions: {
    reset(isDesigner = true) {
      this.formConfig = deepClone({ ...defaultFormConfig });
      this.questions = [];
      this.selectQuestion = null;
      this.isDesigner = isDesigner;
    },
    setQuestions(questions: QuestionType[]) {
      this.questions = questions;
    },
    setSelectQuestion(question: QuestionType | null) {
      this.selectQuestion = question;
    },
  },
});
